package com.gongpingjialoan.activity.car;

import android.app.Activity;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.main.BaseActivity;
import com.gongpingjialoan.bean.car.MyCarBean;

/**
 * Created by Administrator on 2015/11/5.
 */
public class AddRecordMaintainActivity extends BaseActivity {


    private TextView car_detail;

    private MyCarBean myCarBean;

    private String type , mile;

    private ForegroundColorSpan priceForegroundColorSpan;

    private View backV;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_record_layout);
        setTitle("维修保养");
        car_detail = (TextView) findViewById(R.id.car_detail);

        myCarBean = (MyCarBean) getIntent().getSerializableExtra("carbean");
        type = getIntent().getStringExtra("type");
        mile = getIntent().getStringExtra("mile");
        type = "保养";
//        if("small".equals(type)){
//            type = "小保养";
//        }else{
//            type = "大保养";
//        }
        String left = "您的爱车\n"+myCarBean.getModel_zh()+myCarBean.getModel_detail_zh()+"\n完成了";
        String title = left + mile+"公里"+type;
        int l_size = left.length();
        int size = mile.length();
        priceForegroundColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.maintain_price_bg));
        SpannableStringBuilder builder = new SpannableStringBuilder(title);
        builder.setSpan(priceForegroundColorSpan, l_size, l_size + size, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        car_detail.setText(builder);
    }

    @Override
    public void initTitleBar() {
        backV = findViewById(R.id.title_back);
        backV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gotoLikeCar();
            }
        });
    }

    @Override
    public void onBackPressed() {
        gotoLikeCar();
    }

    public void gotomain(View v){
        gotoLikeCar();
    }

    private  void  gotoLikeCar(){
        setResult(Activity.RESULT_OK);finish();
    }

}
